<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>后台管理-登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <script type="text/javascript" src="/lib/haha/core/start.js"></script>
    <link rel="stylesheet" href="/CSS/login.css">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {
            background-image: url("../../images/bg.jpg");
            height: 100%;
            width: 100%;
        }

        #container {
            height: 100%;
            width: 100%;
        }

        input:-webkit-autofill {
            -webkit-box-shadow: inset 0 0 0 1000px #fff;
            background-color: transparent;
        }

        .admin-login-background {
            width: 300px;
            height: 300px;
            position: absolute;
            left: 50%;
            top: 40%;
            margin-left: -150px;
            margin-top: -100px;
        }

        .admin-header {
            text-align: center;
            margin-bottom: 20px;
            color: #ffffff;
            font-weight: bold;
            font-size: 40px
        }

        .admin-input {
            border-top-style: none;
            border-right-style: solid;
            border-bottom-style: solid;
            border-left-style: solid;
            height: 50px;
            width: 300px;
            padding-bottom: 0px;
        }

        .admin-input::-webkit-input-placeholder {
            color: #a78369
        }

        .layui-icon-username {
            color: #a78369 !important;
        }

        .layui-icon-username:hover {
            color: #9dadce !important;
        }

        .layui-icon-password {
            color: #a78369 !important;
        }

        .layui-icon-password:hover {
            color: #9dadce !important;
        }

        .admin-input-username {
            border-top-style: solid;
            border-radius: 10px 10px 0 0;
        }

        .admin-input-verify {
            border-radius: 0 0 10px 10px;
        }

        .admin-button {
            margin-top: 20px;
            font-weight: bold;
            font-size: 18px;
            width: 300px;
            height: 50px;
            border-radius: 5px;
            background-color: #a78369;
            border: 1px solid #d8b29f
        }

        .admin-icon {
            margin-left: 260px;
            margin-top: 10px;
            font-size: 30px;
        }

        i {
            position: absolute;
        }

        .admin-captcha {
            position: absolute;
            margin-left: 205px;
            margin-top: -40px;
        }
    </style>
</head>

<body>
    <div id="container">
        <div></div>
        <div class="admin-login-background">
            <div class="admin-header">
                <span>后台管理-登录</span>
            </div>
            <form class="layui-form" action="">
                <div>
                    <i class="layui-icon layui-icon-username admin-icon"></i>
                    <input type="text" name="id" placeholder="请输入用户名" autocomplete="off"
                        class="layui-input admin-input admin-input-username">
                </div>
                <div>
                    <i class="layui-icon layui-icon-password admin-icon"></i>
                    <input type="password" name="pwd" placeholder="请输入密码" autocomplete="new-password"
                        class="layui-input admin-input">
                </div>
                <button class="layui-btn admin-button" lay-submit lay-filter="login">登 录</button>
            </form>
        </div>
    </div>
    <!-- 登录弹窗 -->
    <div id='updatePassword' style="display: none;">
        <div class="login_box b_radius">
            <p><label for="oldPassWord">旧密码:</label><input id="oldPassWord" type="password" /></p>
            <p><label for="newPassWord">重置密码:</label><input id="newPassWord" type="password" /></p>
            <p><label for="passWordTwo">确认密码:</label><input id="passWordTwo" type="password" /></p>
            <button class="b_radius" id='sureUpdatePassword'>确认重置</button>
        </div>
    </div>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script>

        //手动进入 登录页面 如果有token-->跳转到后台首页

        // console.log(shared.getCookie('token'))

        //     if (shared.getCookie('token')!=='') {
        //             // 跳转到首页
        //             location.href = '/admin/index.html'
        //         }
        var popbox;
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;

            // 登录过期的时候，跳出ifram框架
            if (top.location != self.location) top.location = self.location;
            form.render();
            // 进行登录操作
            form.on('submit(login)', function (data) {
                data = data.field;
                id = data.id
                pwd = data.pwd
                if (data.id == '') {
                    layer.msg('用户名不能为空');
                    return false;
                }
                if (data.pwd == '') {
                    layer.msg('密码不能为空');
                    return false;
                }
                shared.ajaxPost(config.loginUrl, { account: id, password: pwd }, function callback(res) {
                    console.log(res)
                    if (res == "1") {
                        popbox = layer.open({
                            title: '修改密码',
                            icon: 1,
                            type: 1,
                            anim: 2,
                            skin: 'layui-layer-rim', //加上边框
                            area: ['400px', '420px'], //宽高
                            content: $('#updatePassword'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                        });
                        $('#sureUpdatePassword').off().on('click', function () {
                            if (!$('#oldPassWord').val()) {
                                layer.msg('请输入旧密码');
                                return;
                            }
                            if (!$('#newPassWord').val()) {
                                layer.msg('请输入重置密码');
                                return;
                            }
                            if (!$('#passWordTwo').val()) {
                                layer.msg('请输入确认密码');
                                return;
                            }
                            if ($('#newPassWord').val() != $('#passWordTwo').val()) {
                                layer.msg('密码输入不一致');
                                return;
                            }
                            shared.ajaxPost(config.updatePassword, {
                                id: id, pwd: $('#oldPassWord').val(), newPwd: $('#newPassWord').val(),
                                newPwdConfirm: $('#passWordTwo').val()
                            }, function callback(res) {
                                layer.close(popbox);
                                console.log(res)
                                console.log(1111)
                                shared.setCookie('mydx_token', res.mydx_token);
                                shared.setCookie('user_name', res.user_name);
                                layer.msg('登录成功', { time: 1000 }, function () {
                                    window.location = '../../index.html';
                                });
                            })
                        })
                    } else {
                        shared.setCookie('mydx_token', res.mydx_token);
                        shared.setCookie('user_name', res.user_name);
                        layer.msg('登录成功', { time: 1000 }, function () {
                            window.location = '../../index.html';
                        });
                    }

                    return false;
                })
                return false;
            });
        });
    </script>
</body>

</html>